package com.gw.quotes.net.service;

import org.ksoap2.serialization.SoapObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.gw.quotes.entity.business.ProjectInfoEntity;
import com.gw.quotes.net.NewException;
import com.gw.quotes.net.Request;
import com.gw.quotes.net.Response;

/**
 * 项目信息 getProjectinfo
 * 
 * @author Administrator
 *
 */
public class ProjectInfoQueryServiceImpl extends WebBaseServiceImpl {

	@Override
	public Response setResponse() {
		return new Response();
	}

	@Override
	public void checkParam(Request request) throws NewException {
		if (request == null) {
			throw new NewException(Response.RESULT_ERROR, "传入request不能为空");
		}
		if (checkNull(request.getProjectguid())) {
			throw new NewException(Response.RESULT_ERROR, "项目id不能为空");
		}
		if (request.getProjecttype() == 0) {
			throw new NewException(Response.RESULT_ERROR, "项目类型不能为空");
		}
		if (checkNull(request.getLoginname())) {
			throw new NewException(Response.RESULT_ERROR, "用户登录名不能为空");
		}
		if (checkNull(request.getTicket())) {
			throw new NewException(Response.RESULT_ERROR, "接口凭据不能为空");
		}
	}

	@Override
	public void setParamByRequest(Request request, SoapObject rpc)
			throws NewException {
		rpc.addProperty("arg0", request.getProjectguid());
		rpc.addProperty("arg1", request.getProjecttype());
		rpc.addProperty("arg2", request.getLoginname());
		rpc.addProperty("arg3", request.getTicket());
	}

	@Override
	public String getMethodName() throws NewException {
		return "getProjectinfo";
	}

	@Override
	public void resolveResponse(Object object, Response response)
			throws NewException {
		System.out.println("ProjectInfoEntity:" + object.toString());
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
				.create();
		java.lang.reflect.Type type = new TypeToken<ProjectInfoEntity>() {
		}.getType();
		ProjectInfoEntity result = gson.fromJson(object.toString(), type);
		response.setMsg(result.getMsg());
		response.setResult(result.getResult());
		if ("凭据错误".equals(response.getMsg())) {
			response.setMsg("凭据错误，请重新登录");
		}
		if (response.getResult() == Response.RESULT_SUCCESS) {
			response.setObj(result.getProject());
			System.out.println(response.toString());
		}

	}

	String testStr = "{'result':1,'project':{'endtime':'2014-05-23 16:09:48','buyerorgname':'杭州市上城区清波街道办事处本级','projectguid':'169494aa461a037801461dd900b74ee8','projectGoodList':[{"
			+ "'goodsname':'戴尔 DELL R420服务器 DELL R420服务器',"
			+ "'projectguid':'169494aa461a037801461dd900b74ee8',"
			+ "'projectoptionalList':[{"
			+ "'relativeprice':'-150',"
			+ "'qty':'1',"
			+ "'goodsoptionalname':'2*300G SAS 2.5寸 10K换1TB 7.2K RPM, 6Gbps 近线 SAS 2.5英寸 硬盘 - 热插拔',"
			+ "'projectoptionalguid':'169494aa461a037801461dd900e64eec'}],"
			+ "'goodsguid':'169494aa45f8fedf0145f99082290f1e',"
			+ "'projectaccessorieList':[{"
			+ "'goodsname':'戴尔 软件 Microsoft？ Windows Server？ 2008（2012)标准版',"
			+ "'projectaccessoryguid':'169494aa461a037801461dd900e64eea',"
			+ "'projectgoodsguid':'169494aa461a037801461dd900d64ee9',"
			+ "'qty':1,"
			+ "'agreementprice':'5500',"
			+ "'imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/4/24/1398329497338_standardpath_factpath.jpg'}],"
			+ "'projectgoodsguid':'169494aa461a037801461dd900d64ee9',"
			+ "'priceguid':'169494aa45f8fedf0145f9cdb5e528a8',"
			+ "'agreementprice':'12500',"
			+ "'imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/4/24/1398308383431_standardpath_factpath.jpg'}],'projecttype':2,'qty':'1',"
			+ "'quotationcount':22,"
			+ "'projectname':'杭州市上城区清波街道办事处本级议价项目',"
			+ "'projectcode':'HZZFCG-YJ-2014-19339',"
			+ "'goodsclassname':'服务器','projectquotationList':[{"
			+ "'projectguid':'169494aa461a037801461dd900b74ee8',"
			+ "'price':'12500',"
			+ "'quotationtime':'2014-08-11 17:30:40',"
			+ "'accquotations':[{"
			+ "'projectguid':'169494aa461a037801461dd900b74ee8',"
			+ "'price':'5500',"
			+ "'projectaccessoryguid':'169494aa461a037801461dd900e64eea',"
			+ "'quotationtime':'2014-08-11 17:30:40',"
			+ "'totalpric':'5500',"
			+ "'quotationguid':'8a80808a47c467c20147c467c2530000',"
			+ "'accquotationguid':'8a80808a47c467c20147c467c2530001',"
			+ "'supplierguid':'1694949e2f707775012f70e959770094'},{"
			+ "'projectguid':'169494aa461a037801461dd900b74ee8',"
			+ "'price':'22000',"
			+ "'projectaccessoryguid':'169494aa461a037801461dd900e64eeb',"
			+ "'quotationtime':'2014-08-11 17:30:40',"
			+ "'totalpric':'22000',"
			+ "'quotationguid':'8a80808a47c467c20147c467c2530000',"
			+ "'accquotationguid':'8a80808a47c467c20147c467c2530002',"
			+ "'supplierguid':'1694949e2f707775012f70e959770094'}],"
			+ "'totalpric':'39000',"
			+ "'quotationguid':'8a80808a47c467c20147c467c2530000',"
			+ "'projectgoodsguid':'169494aa461a037801461dd900d64ee9','isbid':0,'supplierguid':'1694949e2f707775012f70e959770094'}]}}";

}
